﻿




//通过时间戳获取时间
function getDate(d){
	var date =  new Date(d);
	    var y = 1900+date.getYear();
	    var m = "0"+(date.getMonth()+1);
	    var d = "0"+date.getDate();
	    return y+"-"+m.substring(m.length-2,m.length)+"-"+d.substring(d.length-2,d.length);
}

//存值
stringify=function (obj,data){
	
	return window.localStorage.setItem(obj, JSON.stringify(data));
	
}
//取值
parse=function (obj){
	
	return JSON.parse(localStorage.getItem(obj));
}


//获取路径
getParam=function (name) {
	var url = location.href;
	if (url != null && url.indexOf("?") != -1) {
		var a = url.split("?");
		var a1 = a[1].split("&");
		for (var f = 0; f < a1.length; f++) {
			var a2 = a1[f].split("=")[0];
			if (a2 == name) {
				return a1[f].split("=")[1];
			}
		}
	}
}

//删除数组中某一个元素
Array.prototype.remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
      this.splice(index, 1);
    }
  };


//获取当前时间
getDateTime=function(){
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day=date.getDate();
    var hours=date.getHours();
    var minu=date.getMinutes();
    var second=date.getSeconds();
//判断是否满10
    var arr=[month,day,hours,minu,second];
    arr.forEach(item=>{
        item< 10?"0"+item:item;
    })
    var dataFormat = year+'-'+arr[0]+'-'+arr[1]+' '+arr[2]+':'+arr[3]+':'+arr[4]
	return dataFormat;
}



//将时间转为年月日
function renderTime(date) {
    var date1 = new Date(date).toJSON();
    var date = new Date(+new Date(date1)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
    date.substr(0,10); //接取2020-04-02
    return date

}


// 返回格式为xx天xx小时xx分钟  计算时间差
function timeDifference(faultDate, completeTime) {
    var stime = Date.parse(new Date(faultDate));
    var etime = Date.parse(new Date(completeTime));
    // 两个时间戳相差的毫秒数
    var usedTime = etime - stime;
    // 计算相差的天数
    var days = Math.floor(usedTime / (24 * 3600 * 1000));
    // 计算天数后剩余的毫秒数
    var leave1 = usedTime % (24 * 3600 * 1000);
    // 计算出小时数
    var hours = Math.floor(leave1 / (3600 * 1000));
    // 计算小时数后剩余的毫秒数
    var leave2 = leave1 % (3600 * 1000);
    // 计算相差分钟数
    var minutes = Math.floor(leave2 / (60 * 1000));
    var time = days + "天" + hours + "时" + minutes + "分";
    return time;
}




//添加操作日志表
addOperationlog=function (item){
    Operationlog(item,2)
}
//删除操作日志表
function delOperationlog(item){
    Operationlog(item,3)
}
//查询操作日志表
selOperationlog=function (item){
    Operationlog(item,5)
}
//修改操作日志表
updOperationlog=function (item){
    Operationlog(item,4)
}




//添加数据         item列表名  type类型
Operationlog=function (tablename,type){
    var create=parse("user");//从localStorage里取值

     var mid=create.user_id;//获取登录用户的id
    $.ajax({
        url : '/OperationlogController/addOperationlog',
        type : "post",
        dataType : "json",
        data : {"mid":mid,"tablename":tablename,"type":type},
        success : function(data) {

        }

    })

}

